package com.eight.controller.api;


import com.eight.pojo.SysToDo;
import com.eight.service.ToDoService;
import com.eight.vo.ComResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("system/api/todo")
public class ToDoApi {

    @Autowired private ToDoService toDoService;

    /**
     * 查询所有代办
     * @return 返回所有代办
     */
    @PostMapping("selectAllToDo")
    public ComResult selectAllTodo(){
        return new ComResult(2000,"查询所有代办",toDoService.selectSevenToDo());
    }

    /**
     * 修改代办状态
     * @param toDoEntity 那个ToDo
     * @return 返回结果
     */
    @PostMapping("updateToDo")
    public ComResult updateToDo(@RequestBody SysToDo toDoEntity){
        if (toDoEntity.getStatusId()==0){
            toDoEntity.setStatus("true");
            toDoEntity.setStatusId(1);
        }else {
            toDoEntity.setStatus("false");
            toDoEntity.setStatusId(0);
        }
        return new ComResult(2000,"修改代办",toDoService.updateById(toDoEntity));
    }

    /**
     * 添加代办
     * @param toDoEntity 代办的信息
     * @return 返回结果
     */
    @PostMapping("addToDo")
    private ComResult addToDo(@RequestBody SysToDo toDoEntity){
        toDoEntity.setStatus("false");
        toDoEntity.setStatusId(0);
        return new ComResult(2000,"添加代办",toDoService.save(toDoEntity));
    }

    /**
     * 删除代办
     * @param id 被删的代办id
     * @return 返回结果
     */
    @PostMapping("deleteToDo/{id}")
    private ComResult deleteToDo(@PathVariable("id") int id){
        return new ComResult(2000,"删除代办",toDoService.removeById(id));
    }

}
